<?php
require("../models/webconfig.php");
require("../models/class.connection.php");
require("../models/repositories/class.ProductRepository.php");
require("../models/entities/class.ProductEntity.php");
include("../library/library.pager.php");

$func = new ProductRepository();
$cur = 1;
if (isset($_GET['page'])) {
    if (is_numeric($_GET['page']))
        $cur = $_GET['page'];
}
$totalItem = 0;
$perPageItem = 9;
$list = $func->GetMostSoldProductList($cur, $perPageItem, $totalItem);
$link = GenerateLink($totalItem, 5, $perPageItem, $cur);
?>
<div class="productContent">
    <div class="loading"></div>
    <div class="pagination pagination-left">
        <div class="results">
            <span>
                Kết quả từ:<?php echo (($cur - 1) * $perPageItem + (count($list) > 0 ? 1 : 0)); ?> - <?php echo (($cur - 1) * $perPageItem + count($list)); ?> cua <?php echo $totalItem; ?>
            </span>
        </div>
        <ul class="pager"><?php echo $link ?></ul>
    </div>
    <div class="clearall"></div>
</div>
<table id='tblProducts' >
    <?php
    $count = 0;
    while ($count < count($list)) {
    ?>
        <tr class='productsRow'>
        <?php
        for ($i = $count; $i < count($list); $i++) {
        ?>
            <td style="padding:20px 10px 0 10px;float:left;width:206px;height:260px;text-align:center;">
                <div><a class="link1" href="#"><?php echo $list[$i]->Name_s ?></a></div>
                <div class="clearall" style="margin-top:10px;"></div>
                <div style="width:207px; text-align:center; border:1px solid #ebeaea; padding:5px 0 5px 0;">
                    <a href="../views/detail.php?id=<?php echo $list[$i]->Code_s; ?>"><img class="product1" alt="" src="../content/images/Products/<?php echo $list[$i]->Code_s; ?>/<?php
            $spilit = explode('|', $list[$i]->ImageSrc_s);
            echo $spilit[0];
        ?>" /></a>
            </div>
            <div class="clearall" style="margin-top:10px;"></div>
            <div style="float:left; width:167px; padding:0 20px 0 20px;">
                <table cellpadding="0" cellspacing="0" border="0" class="cont_body_table_2" style="float:left; width:97px;">
                    <tr>
                        <td><img src="../content/images/cont_body_corn_tl_2.gif" border="0" alt="" width="10" height="10" /></td>
                        <td width="100%" class="cont_body_tall_t_2"><img src="../../Content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
                        <td><img src="../content/images/cont_body_corn_tr_2.gif" border="0" alt="" width="10" height="10" /></td>
                    </tr>
                    <tr>

                        <td class="cont_body_tall_l_2"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
                        <td width="100%" class="cont_body_td_2"><span class="productSpecialPrice"><?php echo $list[$i]->Price_f ?><br />VNĐ</span></td>
                        <td class="cont_body_tall_r_2"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
                    </tr>
                    <tr>
                        <td><img src="../content/images/cont_body_corn_bl_2.gif" border="0" alt="" width="10" height="10" /></td>
                        <td width="100%" class="cont_body_tall_b_2"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
                        <td><img src="../content/images/cont_body_corn_br_2.gif" border="0" alt="" width="10" height="10" /></td>
                    </tr>
                </table>
                <div style="float:left; width:55px; margin:0 0 0 15px;">
                    <a href="../views/detail.php?id=<?php echo $list[$i]->Code_s; ?>">
                        <div class="detail">
                            Chi tiết
                        </div>
                    </a>
                    <div class="clearall"></div>
                    <a href="../views/Cart.php?id=<?php echo $list[$i]->Code_s; ?>">
                        <div class="addToCart" style="margin:5px 0 0 0; cursor:pointer;">
                            Mua
                        </div>
                    </a>
                </div>
            </div>
        </td>
        <?php
                                                                                       if (++$count % 3 == 0)
                                                                                           break;
                                                                                   }
        ?>
                                                                               </tr>
    <?php
                                                                               }
    ?>

</table>


